﻿using Domain.Entity.sys;
using Domain.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Application.BusinessTypeService;
using Application.CodeRuleService;

namespace WMSManage.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]//需要鉴权
    public class BusinessTypeController : ControllerBase
    {
        private readonly IBusinessTypeService businessTypeService;

        public BusinessTypeController(IBusinessTypeService businessTypeService)
        {
            this.businessTypeService = businessTypeService;
        }

        /// <summary>
        /// 分页查询业务类型信息
        /// </summary>
        /// <param name="typename">类型名称</param>
        /// <param name="status">状态</param>
        /// <param name="field">方向</param>
        /// <param name="createname">创建人</param>
        /// <param name="CurrentPage">当前页</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<FenYe<BusinessType>> GetBusinessType(string? typename, int? status, string? field, string? createname, int CurrentPage)
        {
            FenYe<BusinessType> fenYe = new FenYe<BusinessType>()
            {
                CurrentPage = CurrentPage,
            };
            return await businessTypeService.GetBusinessType(fenYe,typename,status,field,createname);
        }


        /// <summary>
        /// 添加业务类型信息
        /// </summary>
        /// <param name="addBusinessTypeDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddBusinessType(AddBusinessTypeDto addBusinessTypeDto)
        {
            return  await businessTypeService.AddBusinessType(addBusinessTypeDto);
        }



        /// <summary>
        /// 根据id业务类型信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BusinessType> GetBusinessTypeById(int id)
        {
            return await businessTypeService.GetBusinessTypeById(id);
        }


        /// <summary>
        /// 修改业务类型信息
        /// </summary>
        /// <param name="updateBusinessTypeDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateBusinessType(UpdateBusinessTypeDto updateBusinessTypeDto)
        {
            return await businessTypeService.UpdateBusinessType(updateBusinessTypeDto);
        }


        /// <summary>
        /// 删除业务类型信息
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> DeleteBusinessType(int id)
        {
            return await businessTypeService.DeleteBusinessType(id);
        }


        /// <summary>
        /// 根据方向查询业务类型
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<BusinessType>> GetBusinessTypes(string field)
        {
            return await businessTypeService.GetBusinessTypes(field);
        }
    }
}
